/*
 * Copyright © 2010 SenseForce.com.
 * The Software shall be used for Good, not Evil.
 */

package com.senseforce.classes;

import java.util.Date;

/**
 *
 * @author jcccn
 * @site http://www.senseforce.com/
 */
public class TestThreads implements Runnable {
    private static SynchronizedAccount account;
    int time;
    boolean isGood;
    public TestThreads(boolean isGood) {
//        account.Owner = "jcccn";
//        account.amount = 8888.8f;
        this.isGood = isGood;
        if (isGood) {
            time = 2000;
        }
        else {
            time = 5000;
        }
    }
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                String tag;
                if(isGood) {
                    account.deposit(100);
                    tag = ":thread for add:";
                }
                else {
                    account.withdraw(100);
                    tag = ":thread2:";
                }
                System.out.println(new Date(System.currentTimeMillis()) + tag + account.Owner + ":" + account.amount);
                Thread.sleep(time);
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }

    static public void test(String args[]) {
        account = null;
        account = new SynchronizedAccount("jcccn", 0.0f);
        Thread thread1 = new Thread(new TestThreads(true));
        thread1.start();
        Thread thread2 = new Thread(new TestThreads(false));
        thread2.start();
    }

}
